<template>
  <div class="outer-padding">
    <div class="ds-title pd-bottom--32">听课与评课</div>
    <map-school></map-school>
    <div class="outer-title pd-bottom--32">课程列表</div>
    <listen-choose></listen-choose>
    <div class="list-list">
      <div class="list-item" v-for="item in list" :key="item.id" @click="goVideoPage(item)">
        <img class="list-item__img" :src="item.img" alt="" />
        <p class="list-item__title">{{ item.title }}</p>
        <p class="list-item__text">
          <span>教师：</span>
          <span class="list-item__text--res">{{ item.username }}</span>
        </p>
        <p class="list-item__text">
          <span>教室：</span>
          <span class="list-item__text--res">{{ item.classroom }}</span>
        </p>
        <p class="list-item__text">
          <span>班级：</span>
          <span class="list-item__text--res">{{ item.className }}</span>
        </p>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
  import { defineComponent, reactive, toRefs, ref, onMounted } from 'vue'
  import { DynamicTable, TableQueryHeader } from '@/components/dynamic-table'
  import { useRoute, useRouter } from 'vue-router'
  import { useStore } from '@/store'
  import MapSchool from '@/layout/header/components/map-school.vue'
  import ListenChoose from './components/listen-choose.vue'
  import { getCourseList } from '@/api/homepage/index'

  export default defineComponent({
    name: 'Listencomponent',
    components: {
      MapSchool,
      ListenChoose,
    },
    setup() {
      const tableRef = ref<InstanceType<typeof DynamicTable>>()

      const valueDate = ref<moment.Moment[]>([])

      const route = useRoute()

      const router = useRouter()

      const store = useStore()

      const state = reactive({
        list: [] as any,
      })

      /**
       * @description 加载表格数据
       */

      onMounted(async () => {
        getData({})
      })

      const getData = async (params) => {
        console.log(params)
        const res = await getCourseList(params)
        state.list = res.list
      }

      const goVideoPage = (item) => {
        // window.open(`#/screen?id=${item.id}`, '_blank')
        router.push(`/screen?id=${item.id}`)
      }

      return {
        ...toRefs(state),
        tableRef,
        goVideoPage,
      }
    },
  })
</script>
<style lang="less" scoped>
  .list-list {
    display: flex;
    flex-wrap: wrap;
    // justify-content: space-between;

    &:after {
      content: '';
      width: 188px;
    }

    .list-item {
      width: 186px;
      height: 228px;
      padding: 12px;
      margin-right: 24px;
      margin-bottom: 24px;
      display: flex;
      flex-direction: column;
      color: #666;
      cursor: pointer;
      &:hover {
        background: #f9f9f9;
      }

      .list-item__img {
        width: 162px;
        height: 90px;
        border-radius: 4px;
      }

      .list-item__title {
        font-size: 16px;
        color: #333;
        padding: 12px 0 8px 0;
        font-weight: bold;
      }

      .list-item__text {
        color: #999;
        display: flex;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;

        .list-item__text--res {
          color: #666;
        }
      }
    }
  }
</style>
